<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>改变文件所属的组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.chgrp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">chgrp</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">chgrp</span> &mdash; <span class="dc-title">改变文件所属的组</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.chgrp-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>chgrp</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$group</code></span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   尝试将文件 <code class="parameter">filename</code> 所属的组改成
   <code class="parameter">group</code>（通过组名或组 ID
   指定）。
  </p>
  <p class="para">
   只有超级用户可以任意修改文件的组，其它用户可能只能将文件的组改成该用户自己所在的组。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.chgrp-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       文件的路径。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">group</code></dt>

     <dd>

      <p class="para">
       组的名称或数字。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.chgrp-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.chgrp-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2762">
    <p><strong>Example #1 改变文件所属的组</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'shared_file.txt'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"%s's&nbsp;Group&nbsp;ID&nbsp;@&nbsp;%s:&nbsp;%d\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filename</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'r'</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">filegroup</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">chgrp</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">clearstatcache</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">//&nbsp;do&nbsp;not&nbsp;cache&nbsp;filegroup()&nbsp;results<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$filename</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'r'</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">filegroup</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.chgrp-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数不能作用于<a href="features.remote_files.html" class="link">远程文件</a>，被检查的文件必须是可通过服务器的文件系统访问的。</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">当启用
<a href="features.safe_mode.html" class="link">安全模式</a>时，
PHP 会检查被操作的文件或目录是否与被执行的脚本有相同的 UID（所有者）。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.chgrp-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="chown.html" class="function" rel="rdfs-seeAlso">chown()</a> - 改变文件的所有者</span></li>
    <li class="member"><span class="function"><a href="chmod.html" class="function" rel="rdfs-seeAlso">chmod()</a> - 改变文件模式</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>